import 'package:hrf_app/common/widgets/text_input_add.dart';
import 'package:hrf_app/common/widgets/text_input_image_edit.dart';
import 'package:hrf_app/common/widgets/text_input_multiple_add.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:image_picker/image_picker.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';

import 'index.dart';

class ProjectBugAddPage extends GetView<ProjectBugAddPageController> {
  const ProjectBugAddPage({super.key});

  // 主视图
  Widget _buildView() {
    return ListView(
      children: [
        TextInputAdd(
          leftLabel: "项目:",
          readOnly: true,
          required: true,
          isRightIconShow: true,
          rightIconTapCallBack: () {
            controller.selectProjectListDialog("", "projectId", "项目");
          },
          hintText: "请选择项目",
          controller: controller.projectController,
          contentAlignment: TextAlign.end,
        ),
        TextInputAdd(
          leftLabel: "标题:",
          required: true,
          rightIconTapCallBack: () {},
          hintText: "请输入标题",
          controller: controller.titleController,
          contentAlignment: TextAlign.end,
        ),
        TextInputMultipleAdd(
          leftLabel: "内容:",
          hintText: "请输入内容",
          controller: controller.contentController,
          contentAlignment: TextAlign.start,
        ),
        TextInputAdd(
          leftLabel: "优先级:",
          readOnly: true,
          required: true,
          isRightIconShow: true,
          rightIconTapCallBack: () {
            controller.selectPriorityListDialog("", "projectId", "优先级");
          },
          hintText: "请选择优先级",
          controller: controller.priorityController,
          contentAlignment: TextAlign.end,
        ),
        TextInputAdd(
          leftLabel: "指派人:",
          readOnly: true,
          required: true,
          isRightIconShow: true,
          rightIconTapCallBack: () {
            controller.editAssignUserDialog("", "assignUserName", "指派人");
          },
          hintText: "请选择人员",
          controller: controller.assignUserController,
          contentAlignment: TextAlign.end,
        ),
        TextInputImageEdit(
          labelText: "附件:",
          isShowAdd: true,
          isShowDel: true,
          labelTextColor: Colors.black,
          uploadFileModelList: controller.uploadFileModelList,
          delCallBack: (index){controller.delImage(index);},
          addCallBack: (dynamic param) {
            // 弹出底部弹窗选择相机或相册
            Get.bottomSheet(
              Container(
                height: 150,
                alignment: Alignment.center,
                color: Colors.white,
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    ListTile(
                      leading: const Icon(Icons.camera),
                      title: const Text("相机"),
                      onTap: () {
                        controller.selectPhoto(ImageSource.camera);
                        Get.back(); // 关闭底部弹窗
                      },
                    ),
                    ListTile(
                      leading: const Icon(Icons.photo_library),
                      title: const Text("相册"),
                      onTap: () {
                        controller.selectMultiImage();
                        Get.back(); // 关闭底部弹窗
                      },
                    ),
                  ],
                ),
              ),
            );
          },
        ),
        const SizedBox(
          height: 50,
        ),
        TDButton(
          text: '保存',
          margin: EdgeInsets.symmetric(horizontal: 20),
          size: TDButtonSize.large,
          type: TDButtonType.fill,
          shape: TDButtonShape.rectangle,
          theme: TDButtonTheme.primary,
          onTap: controller.save,
        )
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<ProjectBugAddPageController>(
      init: ProjectBugAddPageController(),
      id: "ProjectBugAddPage",
      builder: (_) {
        return Scaffold(
          appBar: AppBar(title: const Text("新增")),
          body: SafeArea(
            child: _buildView(),
          ),
        );
      },
    );
  }
}
